/////////////////Template Implementation

#define HASHMAP_CLASS			HashMap<Key,Value, Traits>

template <typename Key, typename Value,typename Traits>
inline HASHMAP_CLASS::HashMap()
{
}

template <typename Key, typename Value,typename Traits>
inline HASHMAP_CLASS::~HashMap()
{
}


template <typename Key, typename Value,typename Traits>
inline Value HASHMAP_CLASS::lookup (Key &k)
{
	int i = lookup_entry(k);
	return entries[i].second;
}

template <typename Key, typename Value,typename Traits>
inline int HASHMAP_CLASS::lookup_entry (Key k)
{
	for(UINT32 i=0; i<entries.size(); i++)
	{
		if(t.isequal(entries[i].first, k))
		{
			return i;
		}
	}
	throw Exception(hash_lookup_failed);
}


template <typename Key, typename Value,typename Traits>
inline void HASHMAP_CLASS::insert(Key &k, Value &v)
{
	try
	{
		int i = lookup_entry(k);
		entries[i].second = v;
	}
	catch(Exception e)
	{
		entries.push_back(ENTRY(k,v));
	}
}

template <typename Key, typename Value,typename Traits>
inline void HASHMAP_CLASS::remove(Key &k)
{
	int i = lookup_entry(k);
	entries.erase(entries.begin() + i);
}

template <typename Key, typename Value,typename Traits>
template<class Function>
inline void HASHMAP_CLASS:: foreach(Function fun)
{
	for(UINT32 i=0; i<entries.size(); i++)
	{
		fun(entries[i].first, entries[i].second);
	}
}
